"""
Task 1

Files

Write a script that creates a new output file called myfile.txt and writes the string "Hello file world!" in it.
Then write another script that opens myfile.txt, and reads and prints its contents.
Run your two scripts from the system command line.

Does the new file show up in the directory where you ran your scripts?
- Yes
What if you add a different directory path to the filename passed to open?
- It will create or open a file in specified directory if it exists

Note: file write methods do not add newline characters to your strings; add an explicit ‘\n’ at the end of the
string if you want to fully terminate the line in the file.
"""
import os

directory_path = os.getcwd()
folder_name = os.path.basename(directory_path)

if folder_name == "Beetroot_20220728_PY_Ivan_Samchuk":
    # write to file
    with open("lesson_11_work_with_files_json/homework/myfile1.txt", "w") as file:
        file.write("Hello file world!\nScript triggered from root folder \n")
    # read file
    with open("lesson_11_work_with_files_json/homework/myfile1.txt") as file:
        print([text.rstrip() for text in file])

if folder_name == "homework":
    # write to file
    with open("myfile2.txt", "w") as file:
        file.write("Hello file world!\nScript triggered from homework folder \n")
    # read file
    with open("myfile2.txt") as file:
        print([text.rstrip() for text in file])
